
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../application.dart';

class Recommend extends StatelessWidget {
  final List recomendList;

  Recommend({Key key, this.recomendList}):super(key: key);

  Widget _titleWidget(){
    return Container(
      alignment: Alignment.centerLeft,
      padding: EdgeInsets.fromLTRB(10, 2, 0, 2),
      decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
              bottom: BorderSide(
                  width: 1,
                  style: BorderStyle.solid,
                  color: Colors.black12
              )
          )
      ),
      child: Text(
        '商品推荐',
        style: TextStyle(color: Colors.pink),
      ),
    );
  }
  Widget _item(context,index){
    return InkWell(
      onTap: (){
        Application.router.navigateTo(context, 'detail?id=${100}');
      },
      child: Container(
        height: ScreenUtil().setHeight(330),
        width: ScreenUtil().setWidth(250),
        padding: EdgeInsets.all(8),
        decoration: BoxDecoration(
            color: Colors.white,
            border: Border(
              left: BorderSide(color: Colors.black12,width: 1),
            )
        ),
        child: Column(
          children: <Widget>[
            Image.network(this.recomendList[index]['image_url'],fit: BoxFit.cover,),
            Text('${this.recomendList[index]['newPrice']}'),
            Text(
              '${this.recomendList[index]['price']}',
              style: TextStyle(
                  decoration: TextDecoration.lineThrough,
                  color: Colors.grey
              ),
            )
          ],
        ),
      ),
    );
  }

  Widget _recomendList(){

    return Container(
      height: ScreenUtil().setHeight(330),
      child: ListView.builder(
          itemCount: recomendList.length,
          scrollDirection: Axis.horizontal,
          itemBuilder: (context,index){
            return _item(context,index);
          }
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: ScreenUtil().setHeight(380),
      margin: EdgeInsets.only(top: 10),
      child: Column(
        children: <Widget>[
          _titleWidget(),
          _recomendList()
        ],
      ),
    );
  }
}

